//
//  ImageViewController.m
//  MyMovie
//
//  Created by apple on 16/5/14.
//  Copyright © 2016年 ljp. All rights reserved.
//

#import "ImageViewController.h"
#import "MyBigImageViewController.h"




@interface ImageViewController ()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
{
    NSMutableArray *_imageArray;
}
@end

@implementation ImageViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self loadImages];
}

-(void)loadImages {

    NSArray *array = [JSONDataService loadJSONFielWithName:@"image_list"];
    _imageArray = [[NSMutableArray alloc] init];
    for (NSDictionary *dic in array) {

        NSURL *url = [NSURL URLWithString:dic[@"image"]];
        [_imageArray addObject:url];
    }

}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return _imageArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ImageCell" forIndexPath:indexPath];
    UIImageView *imageView = [cell.contentView viewWithTag:112233];

    [imageView sd_setImageWithURL:_imageArray[indexPath.item]];

    //设置单元格的边框颜色
    cell.layer.borderColor = [UIColor redColor].CGColor;
    cell.layer.borderWidth = 2;
    //设置单元格的视角(从哪里开始弯曲)
    cell.layer.cornerRadius = cell.width/2;

    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat width = (KScreenWidth-50)/4;
    return CGSizeMake(width-0.1, width-0.1);
}
//实现选中单元格方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    MyBigImageViewController *myBigImageViewController = [[MyBigImageViewController alloc] init];
    myBigImageViewController.urlArray = _imageArray;
    myBigImageViewController.indexPath = indexPath;
    [self.navigationController pushViewController:myBigImageViewController animated:YES];
    

}

@end
